
*****Open Dataset
use "replication_conjoint_final_Vietnam.dta", clear

***Generate Vietnam subpanel for Figure 1: Overall acceptance levels


hist like, percent xlabel(1 "1 = Low" 2 3 4 5 6 7 "7 = High") scheme(plotplain) xtitle("Acceptance") ytitle("Percentage of Respondents - Vietnam") discrete aspectratio(1) name(graph1, replace)


***Conjoint results for Vietnam - Figure 2 and column 1 in Table 2

reg accept i.female i.age i.education i.income i.ethnicity i.reason, cluster(respondent)


foreach x of numlist 0(1)1 {
lincom  `x'.female 
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.female"
matrix resmat = nullmat(resmat) \ coef
}

foreach x of numlist 1(1)4 {
lincom  `x'.age
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.age"
matrix resmat = nullmat(resmat) \ coef
}

foreach x of numlist 1(1)6 {
lincom  `x'.education 
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.education"
matrix resmat = nullmat(resmat) \ coef
}

*income
foreach x of numlist 1(1)4 {
lincom  `x'.income 
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.income"
matrix resmat = nullmat(resmat) \ coef
}

* ethnicity

foreach x of numlist 1(1)5 {
lincom  `x'.ethnicity
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.ethnicity"
matrix resmat = nullmat(resmat) \ coef
}

*reason
foreach x of numlist 1(1)5 {
lincom  `x'.reason 
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.reason"
matrix resmat = nullmat(resmat) \ coef
}


mat2txt , matrix(resmat) saving("migrant_choice_all_in_one.txt") replace
matrix drop resmat

**Generate Figure 2
clear
set more off
insheet using "migrant_choice_all_in_one.txt",  clear


gen varname=_n
replace varname = 24 in 26
replace varname = 25 in 24
replace varname = 26 in 25
list


#delimit;
label define varlab 
1"Male" 2 "Female" 3 "18-25 years"
4 "34-48 years" 5 "52-65 years" 6 "Above 70"
7 "No formal education" 8 "Primary school"
9 "Secondary school" 10 "Tertiary school" 11 "Technical school"
12 "University degree" 13 "Very low" 14 "Low"
15 "Sufficient" 16 "High"
17  "Kinh" 18 "Mường" 
19 "Tày" 20 "Khmer" 21 "Hmong" 
22 "Persecution" 23 "Family reunification" 
25 "Storm/flood" 26 "Drought" 24 "Economic opportunities";
#delimit cr
label values varname varlab


gen group=_n
replace group = 24 in 26
replace group = 25 in 24
replace group = 26 in 25

#delimit;
label define groupings 
1" " 2 "{bf:Gender}" 3 " " 4 " " 5 " " 6 "{bf:Age}" 7 " " 8 " " 9 " " 10 " " 11 " " 12 "{bf:Education}"
13 " " 14 " " 15 " " 16 "{bf:Income}" 17 " " 18 " " 19 " " 20 " " 21 "{bf:Ethnicity}" 22" " 23 " " 24 " " 25 " " 26 "{bf:Reason}";
#delimit cr
label values group groupings
 
gen clo=c1-1.96*c2
gen chi=c1+1.96*c2


#delimit;
twoway (rspike clo chi varname, lcolor(black) lpattern(shortdash) horizontal ytitle("") yaxis(1) ylabel(1(1)26,valuelabel angle(0)) xlabel(-0.2(0.1)0.3, format(%3.2f)) xtitle("Change in the Probability of Accepting Migrant in City") 
xline(0, lcolor(black))) ||  (scatter group c1, ytitle("", axis(2)) ylabel(1(1)26, valuelabel axis(2)) yaxis(2)  mcolor(black) msymbol(smcircle) msize(small) ytitle("")),  yline(2.5, lpattern(solid) lcolor(black) extend) yline(6.5, lpattern(solid) lcolor(black) extend) yline(12.5, lpattern(solid) lcolor(black) extend) yline(16.5, lpattern(solid) lcolor(black) extend) yline(21.5, lpattern(solid) lcolor(black) extend) legend(off) scheme(plotplain) aspectratio(1);
#delimit cr



******Rating variable as dependent variable - SI Figure 31 and and column 2 in Table 2


use "replication_conjoint_final_Vietnam.dta", clear


reg like i.female i.age i.education i.income i.ethnicity i.reason, cluster(respondent)

foreach x of numlist 0(1)1 {
lincom  `x'.female 
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.female"
matrix resmat = nullmat(resmat) \ coef
}

foreach x of numlist 1(1)4 {
lincom  `x'.age
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.age"
matrix resmat = nullmat(resmat) \ coef
}

foreach x of numlist 1(1)6 {
lincom  `x'.education 
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.education"
matrix resmat = nullmat(resmat) \ coef
}

*income
foreach x of numlist 1(1)4 {
lincom  `x'.income 
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.income"
matrix resmat = nullmat(resmat) \ coef
}

* ethnicity

foreach x of numlist 1(1)5 {
lincom  `x'.ethnicity
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.ethnicity"
matrix resmat = nullmat(resmat) \ coef
}

*reason
foreach x of numlist 1(1)5 {
lincom  `x'.reason 
mat    coef = r(estimate) , r(se)
matrix rownames coef = 	"`x'.reason"
matrix resmat = nullmat(resmat) \ coef
}

mat2txt , matrix(resmat) saving("migrant_choice_like.txt") replace
matrix drop resmat

**making graphs
clear
set more off
insheet using "migrant_choice_like.txt",  clear

gen varname=_n
replace varname = 24 in 26
replace varname = 25 in 24
replace varname = 26 in 25
list

#delimit;
label define varlab 
1"Male" 2 "Female" 3 "18-25 years"
4 "34-48 years" 5 "52-65 years" 6 "Above 70"
7 "No formal education" 8 "Primary school"
9 "Secondary school" 10 "Tertiary school" 11 "Technical school"
12 "University degree" 13 "Very low" 14 "Low"
15 "Sufficient" 16 "High"
17  "Kinh" 18 "Mường" 
19 "Tày" 20 "Khmer" 21 "Hmong" 
22 "Persecution" 23 "Family reunification" 
25 "Storm/flood" 26 "Drought" 24 "Economic opportunities";
#delimit cr
label values varname varlab

gen group=_n
replace group = 24 in 26
replace group = 25 in 24
replace group = 26 in 25

#delimit;
label define groupings 
1" " 2 "{bf:Gender}" 3 " " 4 " " 5 " " 6 "{bf:Age}" 7 " " 8 " " 9 " " 10 " " 11 " " 12 "{bf:Education}"
13 " " 14 " " 15 " " 16 "{bf:Income}" 17 " " 18 " " 19 " " 20 " " 21 "{bf:Ethnicity}" 22" " 23 " " 24 " " 25 " " 26 "{bf:Reason}";
#delimit cr
label values group groupings
 
gen clo=c1-1.96*c2
gen chi=c1+1.96*c2

#delimit;
twoway (rspike clo chi varname, lcolor(black) lpattern(shortdash) horizontal ytitle("") yaxis(1) ylabel(1(1)26,valuelabel angle(0)) xlabel(-1(0.5)1.5, format(%3.2f)) xtitle("Change in the Approval Rating of Migrant in City") 
xline(0, lcolor(black))) ||  (scatter group c1, ytitle("", axis(2)) ylabel(1(1)26, valuelabel axis(2)) yaxis(2)  mcolor(black) msymbol(smcircle) msize(small) ytitle("")), yline(2.5, lpattern(solid) lcolor(black) extend) yline(6.5, lpattern(solid) lcolor(black) extend) yline(12.5, lpattern(solid) lcolor(black) extend) yline(16.5, lpattern(solid) lcolor(black) extend) yline(21.5, lpattern(solid) lcolor(black) extend) legend(off) scheme(plotplain) aspectratio(1);
#delimit cr









